package com.healer.hungery.config;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChildJob2 {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Bean
    public Job childJob2Job(){
        return jobBuilderFactory.get("childJob2Job")
                .start(childJob2step1())
                .next(childJob2step2())
                .build();
    }
    @Bean
    public Step childJob2step1() {
        return stepBuilderFactory.get("childJob2step1").tasklet(new Tasklet() {
            @Override
            public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
                System.out.println("childJob2step1");
                return RepeatStatus.FINISHED;
            }
        }).build();
    }

    @Bean
    public Step childJob2step2() {
        return stepBuilderFactory.get("childJob2step2").tasklet(new Tasklet() {
            @Override
            public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
                System.out.println("childJob2step2");
                return RepeatStatus.FINISHED;
            }
        }).build();
    }
}
